import { Table } from "element-ui";
import tableMixin from "./tableMixin";

/**
 * 单击行选中
 */
const handleRowClick = Table.components.TableBody.methods.handleClick;
Table.components.TableBody.methods.handleClick = function (event, row) {
  if (this.columns[0].type == "selection" && this.columns[0].selectable) {
    const _selectable = this.columns[0].selectable(row);
    if (!_selectable) {
      return;
    }
  }
  const _checkedByRowClick = this.table.$attrs.checkedByRowClick;
  if (_checkedByRowClick == undefined || _checkedByRowClick == true) {
    this.table.toggleRowSelection(row);
    handleRowClick.call(this, event, row);
    this.table.$emit("select", this.table.selection, row);
  } else {
    handleRowClick.call(this, event, row);
  }
};

// 添加mixins
if (Object.prototype.toString.call(Table.mixins) === "[object Array]") {
  Table.mixins.push(tableMixin);
} else {
  Table.mixins = [tableMixin];
}
